package com.epam.photographer.controllers;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.epam.photographer.DAO.IDao;
import com.epam.photographer.model.Album;
import com.epam.photographer.model.PhotoWrapper;
import com.epam.photographer.model.Photographer;

@Component
public class FillController {
	@Autowired
	private IDao dao ;
	
	public void fillDB() throws IOException {
		Photographer anna = new Photographer();
		anna.setId(1);
		anna.setName("Anna");
		anna.setTown("Grodno");
		anna.setLastName("Korotaeva");

		Album album = new Album();
		album.setId(1);
		album.setPhotographerId(1);
		album.setTitle("Parochki");

		PhotoWrapper foto1 = new PhotoWrapper();

		String url1 = "D:/Photographers/1.jpg";
		BufferedImage im = ImageIO.read(new File(url1));
	//	foto1.setPhoto(im);
		foto1.setId(1);
		foto1.setPhotographerId(1);
		foto1.setTitle("SashaLesha");
		foto1.setAlbumId(1);
		foto1.setUrl(url1);

		PhotoWrapper foto2 = new PhotoWrapper();
		String url2 = "D:/Photographers/2.jpg";
		BufferedImage im2 = ImageIO.read(new File(url2));
	//	foto2.setPhoto(im2);
		foto2.setId(2);
		foto2.setPhotographerId(1);
		foto2.setTitle("SashaLesha");
		foto2.setAlbumId(1);
		foto2.setUrl(url2);
		PhotoWrapper foto3 = new PhotoWrapper();
		String url3 = "D:/Photographers/3.jpg";
		BufferedImage im3 = ImageIO.read(new File(url3));
	//	foto3.setPhoto(im3);
		foto3.setId(3);
		foto3.setPhotographerId(1);
		foto3.setTitle("SashaLesha");
		foto3.setAlbumId(1);
		foto3.setUrl(url3);
		PhotoWrapper foto4 = new PhotoWrapper();
		String url4 = "D:/Photographers/4.jpg";
		BufferedImage im4 = ImageIO.read(new File(url4));
	//	foto4.setPhoto(im4);
		foto4.setId(4);
		foto4.setPhotographerId(1);
		foto4.setTitle("SashaLesha");
		foto4.setAlbumId(1);
		foto4.setUrl(url4);
		
		dao.addPhotographer(anna);
		dao.addAlbum(album);
		dao.addPhotoWrapper(foto1);
		dao.addPhotoWrapper(foto2);
		dao.addPhotoWrapper(foto3); 
		dao.addPhotoWrapper(foto4);

	}
}
